use core::mem::{transmute, variant_count};

pub enum SyscallIndex {
    Malloc = 1,
    Free,
    Exit,
    IsExited,
    Print,
    Open,
    Close,
    Read,
    Write,
    Fsize,
    Ftype,
    ListDir,
    DirItemNum,
    IoCtl,
    LSeek,
    Mmap,
    AllocForDma,
    DeallocForDma,
    GetPid,
    SetInitPid,
    Execve,
    ChangeCwd,
    GetCwd,
}

impl From<usize> for SyscallIndex {
    fn from(number: usize) -> Self {
        let syscall_length = variant_count::<Self>();
        if number > syscall_length {
            panic!("Invalid syscall index: {}", number);
        }
        unsafe { transmute(number as u8) }
    }
}
